package cn.edu.gench.learn.util;

import java.sql.*;

/**
 * Created by Administrator on 2017/4/28.
 */
public class ConnectFactory {


    public static Connection getConnection(){

        // 驱动程序名
        String driver = "com.mysql.jdbc.Driver";
        // URL指向要访问的数据库名world
        String url = "jdbc:mysql://127.0.0.1:3306/learn?useUnicode=true&characterEncoding=utf8";
        // 加载驱动程序
        try {
            Class.forName(driver);
            return  DriverManager.getConnection(url, "root", "");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void  close(Connection connection,
                              ResultSet rs,
                              Statement statement){

        try {
            if(rs != null) {
                rs.close();
            }
            statement.close();
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

}
